package com.love.travel.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.love.common.log.annotation.Log;
import com.love.common.log.enums.BusinessType;
import com.love.common.security.annotation.RequiresPermissions;
import com.love.travel.domain.TravelProductComment;
import com.love.travel.service.ITravelProductCommentService;
import com.love.common.core.web.controller.BaseController;
import com.love.common.core.web.domain.AjaxResult;
import com.love.common.core.utils.poi.ExcelUtil;
import com.love.common.core.web.page.TableDataInfo;

/**
 * 产品评价Controller
 * 
 * @author love
 * @date 2025-10-25
 */
@RestController
@RequestMapping("/comment")
public class TravelProductCommentController extends BaseController
{
    @Autowired
    private ITravelProductCommentService travelProductCommentService;

    /**
     * 查询产品评价列表
     */
    @RequiresPermissions("travel:comment:list")
    @GetMapping("/list")
    public TableDataInfo list(TravelProductComment travelProductComment)
    {
        startPage();
        List<TravelProductComment> list = travelProductCommentService.selectTravelProductCommentList(travelProductComment);
        return getDataTable(list);
    }

    /**
     * 导出产品评价列表
     */
    @RequiresPermissions("travel:comment:export")
    @Log(title = "产品评价", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TravelProductComment travelProductComment)
    {
        List<TravelProductComment> list = travelProductCommentService.selectTravelProductCommentList(travelProductComment);
        ExcelUtil<TravelProductComment> util = new ExcelUtil<TravelProductComment>(TravelProductComment.class);
        util.exportExcel(response, list, "产品评价数据");
    }

    /**
     * 获取产品评价详细信息
     */
    @RequiresPermissions("travel:comment:query")
    @GetMapping(value = "/{commentId}")
    public AjaxResult getInfo(@PathVariable("commentId") Long commentId)
    {
        return success(travelProductCommentService.selectTravelProductCommentByCommentId(commentId));
    }

    /**
     * 新增产品评价
     */
    @RequiresPermissions("travel:comment:add")
    @Log(title = "产品评价", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TravelProductComment travelProductComment)
    {
        return toAjax(travelProductCommentService.insertTravelProductComment(travelProductComment));
    }

    /**
     * 修改产品评价
     */
    @RequiresPermissions("travel:comment:edit")
    @Log(title = "产品评价", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TravelProductComment travelProductComment)
    {
        return toAjax(travelProductCommentService.updateTravelProductComment(travelProductComment));
    }

    /**
     * 删除产品评价
     */
    @RequiresPermissions("travel:comment:remove")
    @Log(title = "产品评价", businessType = BusinessType.DELETE)
	@DeleteMapping("/{commentIds}")
    public AjaxResult remove(@PathVariable Long[] commentIds)
    {
        return toAjax(travelProductCommentService.deleteTravelProductCommentByCommentIds(commentIds));
    }
}
